﻿using Ivory;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Paintball.Interfaces;
using Paintball.Libaries;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Paintball
{
    public class Map : IDrawableObject
    {
        //Fields
        protected Texture2D FloorTexture;
        protected List<MapObject> Objects;

        //ctor
        public Map(IEnumerable<MapObject> objects)
        {
            Objects = new List<MapObject>(objects);
            FloorTexture = TileHelper.Tile(Resources.GrassTexture, 10, 10);
        }

        //Methods        
        public void Draw(SpriteBatch batch, GameTime time)
        {
            batch.Begin();

            //Draw the Floor Texture
            batch.Draw(FloorTexture, new Rectangle(0, 0, FloorTexture.Width, FloorTexture.Height), Color.White);

            batch.End();
        }
        public void Update(InputControl input, GameTime time)
        {

        }
        public bool Load()
        {
            return true;
        }

            //Helpers
        public void AddObject(MapObject obj)
        {
            Objects.Add(obj);
        }
        public T GetObjectByName<T>(string name) 
            where T : MapObject
        {
            return (T)Objects.Where(o => o.Name == name).FirstOrDefault();
        }

        public IEnumerable<Sprite> GetObjects()
        {
            return Objects;
        }        
    }
}
